package cn.tedu.carehome.foundation.service.impl;

import cn.tedu.carehome.foundation.ex.ServiceException;
import cn.tedu.carehome.foundation.mapper.CaseFileMapper;
import cn.tedu.carehome.foundation.mapper.GoodlistMapper;
import cn.tedu.carehome.foundation.mapper.MedicineMapper;
import cn.tedu.carehome.foundation.mapper.OlderMapper;
import cn.tedu.carehome.foundation.pojo.dto.GoodlistAddNewDTO;
import cn.tedu.carehome.foundation.pojo.dto.GoodlistUpdateDTO;
import cn.tedu.carehome.foundation.pojo.entity.CaseFile;
import cn.tedu.carehome.foundation.pojo.entity.Goodlist;
import cn.tedu.carehome.foundation.pojo.vo.GoodlistListItemVO;
import cn.tedu.carehome.foundation.pojo.vo.GoodlistStandardVO;
import cn.tedu.carehome.foundation.pojo.vo.MedicineStandardVO;
import cn.tedu.carehome.foundation.pojo.vo.OlderStandardVO;
import cn.tedu.carehome.foundation.restful.JsonPage;
import cn.tedu.carehome.foundation.service.IGoodlistService;
import cn.tedu.carehome.foundation.web.ServiceCode;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class GoodlistServiceImpl implements IGoodlistService {

    @Autowired
    private GoodlistMapper goodlistMapper;


    @Override
    public void addNew(GoodlistAddNewDTO goodlistAddNewDTO) {
        log.debug("开始处理【添加】的业务，参数：{}", goodlistAddNewDTO);

        Goodlist goodlist = new Goodlist();
        BeanUtils.copyProperties(goodlistAddNewDTO, goodlist);
        int rows = goodlistMapper.insert(goodlist);
        if (rows != 1) {
            String message = "添加病例失败，服务器忙，请稍后重试！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERR_INSERT, message);
        }

    }

    @Override
    public void deleteById(Long id) {
        log.debug("开始处理【根据id删除】的业务，参数：{}", id);


        int rows = goodlistMapper.deleteById(id);
        if (rows != 1) {
            String message = "删除病例失败，服务器忙，请稍后重试！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERR_DELETE, message);
        }



    }

    @Override
    public List<GoodlistListItemVO> list() {
        log.debug("开始处理【查询病例列表】的业务，无参数");
        List<GoodlistListItemVO> list = goodlistMapper.list();
        return list;
    }

    @Override
    public List<GoodlistListItemVO> listLimit(String content) {
        log.debug("开始处理【查询病例列表】的业务，无参数");
        if (content == null) {
            content ="";
        }
        List<GoodlistListItemVO> list = goodlistMapper.listLimit(content);
        return list;
    }


}
